package com.tongtong.stsuserapi.controller;

import com.tongtong.stscommon.message.STSMessage;
import com.tongtong.stscommon.proxy.annotation.AutoGetId;
import com.tongtong.stsuserapi.service.base.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags="评论接口")
@RestController
@RequestMapping("/sts/user/comment")
public class CommentController {

	@Autowired
	CommentService commentService;

	@ApiOperation(value="发布评价")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userId", value = "该参数从token中自动获取，无需传入"),
			@ApiImplicitParam(name = "content", value = "评论内容，使用json传输")
	})
	@PostMapping
	@AutoGetId
	STSMessage postComment(Long userId, Long orderId, Integer score,@RequestBody String content) {
		return commentService.postComment(userId,orderId,score,content);
	}

	@ApiOperation(value="删除评价")
	@ApiImplicitParam(name = "userId", value = "该参数从token中自动获取，无需传入")
	@DeleteMapping
	@AutoGetId
	STSMessage deleteComment(Long userId, Long commentId) {
		return commentService.deleteComment(userId,commentId);
	}

	@ApiOperation(value="获取评价和星级")
	@ApiImplicitParam(name = "userId", value = "卖家id")
	@GetMapping
	STSMessage getCommentsAndScore(Long userId) {
		return commentService.getCommentsAndScore(userId);
	}
}
